Automatic closed-loop anesthesia